package com.estar.integaration.Parser;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.estar.integaration.Enum.GroupEnum;
import com.estar.integaration.Util.Util;
import com.estar.integaration.entity.moneyEntity.MaterialComposition;
import com.estar.integaration.entity.moneyEntity.MaterialGroupMoney;
import com.estar.integaration.entity.moneyEntity.MaterialMoney;

import java.io.*;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * Author: YJL
 * Date: 2021/12/16 22:54
 * 生产车间表
 **/
public class MaterialGroupParse {

  public List<MaterialGroupMoney> parseExcel(String excelAddress) {

    List<MaterialGroupMoney> materialGroupMoneyLinkedList = new LinkedList<>();

    ExcelReader excelReader = null;
    List<List<Object>> content = null;

    try(InputStream inputStream = new FileInputStream(new File(excelAddress))){
      excelReader = ExcelUtil.getReader(inputStream,0);
      content = excelReader.read(1,excelReader.getRowCount());

      for(List<Object> list : content){

        String materialCode = String.valueOf(list.get(7));//物料号
        String productRoom = String.valueOf(list.get(10));//生产车间

        Integer productRoomType = -1;

        switch (productRoom){
          case "机加工组":
            productRoomType = 0;
            break;
          case "电气组":
            productRoomType = 1;
            break;
          case "生产一组":
            productRoomType = 2;
            break;
          case "生产二组":
            productRoomType = 3;
            break;
        }
        if(productRoomType == -1){
          continue;
        }

        MaterialGroupMoney materialGroupMoney = new MaterialGroupMoney(Util.getUUID(),materialCode,productRoomType);
        materialGroupMoneyLinkedList.add(materialGroupMoney);
      }

      return materialGroupMoneyLinkedList;

    } catch (FileNotFoundException e) {

      e.printStackTrace();

    } catch (IOException e) {

      e.printStackTrace();

    }

    return null;
  }

  public HashMap<String,Integer> getMaterialCodeProductRoomHashMap(List<MaterialGroupMoney> materialGroupMoniyList){
    HashMap<String,Integer> mCodeProomHashMap = new HashMap<>();
    materialGroupMoniyList.forEach( m -> mCodeProomHashMap.put(m.getMaterialCode(),m.getGroupType()));
    return mCodeProomHashMap;
  }


}
